
//寻找字符串中的异位词
class Solution {
public:
    vector<int> findAnagrams(string s, string p) {
        vector<int> ans;
        int left = 0, right = 0, ss = s.size(), sp = p.size();
        int hash[26];
        if (ss < sp) {
            return {};
        }
        for (auto& ch : p) {
            hash[ch - 'a']++;
        }
        while (right < ss) {
            hash[s[right] - 'a']--; // 进窗口
            while (hash[s[right] - 'a'] < 0) {
                hash[s[left++] - 'a']++;
            }
            if (right - left + 1 == sp) {
                ans.push_back(left);
            }
            right++;
        }
        return ans;
    }
};

